<template>
  <div class="row">
    <div v-for="column in columnList" :key="column._id" class="col-4 mb-4" @click="jump(column._id)" style="cursor: pointer;">
      <div class="card h-100 shadow-sm">
        <div class="card-body text-center">
          <img :src="column.avatar?.url" :alt="column.title" class="round-circle border border-light w-25 my-3">
          <h5 class="card-title">{{column.title}}</h5>
          <p class="card-text">{{column.description}}</p>
          <a href="#" class="btn btn-outline-primary">进入专栏</a>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { ColumnProps } from '@/hooks/testData'
import { defineComponent, PropType, computed } from 'vue'
import { useRouter } from 'vue-router'

import { useStore } from 'vuex'
export default defineComponent({
  name: 'ColumnList',
  props: {
    list: {
      type: Array as PropType<ColumnProps[]>,
      required: true
    }
  },
  setup(props) {
    const router = useRouter()
    const store = useStore()
    const columnList = computed(() => {
      return props.list.map(column => {
        if (!column.avatar) {
          column.avatar = require('@/assets/logo.png')
        }
        return column
      })
    })
    const jump = (id: string) => {
      router.push(`/column/${id}`)
    }
    return {
      columnList,
      jump
    }
  }
})
</script>
